package com.wolves.career.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wolves.career.entity.RealTimeForumComment;
import com.wolves.career.mapper.RealTimeForumCommentMapper;
import com.wolves.career.service.RealTimeForumCommentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 麦翔盛
 * @since 2021-10-27
 */
@Service
public class RealTimeForumCommentServiceImpl extends ServiceImpl<RealTimeForumCommentMapper, RealTimeForumComment> implements RealTimeForumCommentService {

    @Override
    public QueryWrapper<RealTimeForumComment> getCommentQueryWrapper(RealTimeForumComment comment) {
        QueryWrapper<RealTimeForumComment> queryWrapper = new QueryWrapper<>();
        //获取所有需要查询的信息
        String commentId = comment.getCommentId();
        Integer thumbUpNumber = comment.getThumbUpNumber();
        Date commentOnTime = comment.getCommentOnTime();
        String content = comment.getContent();
        String userId = comment.getUserId();
        String topicId = comment.getTopicId();
        if (!StringUtils.isEmpty(commentId)){
            queryWrapper.eq("comment_id",commentId);
        }
        if (!StringUtils.isEmpty(thumbUpNumber)){
            //获取点赞数更高的
            queryWrapper.gt("thumbUpNumber",thumbUpNumber);
        }
        if (!StringUtils.isEmpty(commentOnTime)){
            //创建时间更早的
            queryWrapper.gt("comment_on_time",commentOnTime);
        }
        if (!StringUtils.isEmpty(content)){
            //模糊查询评论内容
            queryWrapper.like("content",content);
        }
        if (!StringUtils.isEmpty(userId)){
            queryWrapper.eq("user_id",userId);
        }
        if (!StringUtils.isEmpty(topicId)){
            queryWrapper.eq("topic_id",topicId);
        }
        return queryWrapper;

    }
}
